/**
 * 系统退货单管理相关js文件
 */
var sysReturnList = {};
var $sysReturnTable = null;
sysReturnList.operation = {};

// 页面初始化
$(function () {
    var fromother = "n";
    if (window.top.window.$("#returnCode").val() != "") {
        $("#quickSearch").val(window.top.window.$("#returnCode").val());
        window.top.window.$("#returnCode").val('');
        fromother = "y";
    }
    //隐藏高级查询
    $("#advSearchPanel").hide();
    //日期控件初始化
    $('.datetimepicker-default').datetimepicker();
    //日期控件默认隐藏
    $(".panel-default .input-group-addon").hide();
    //初始化店铺信息
    setShopValue();
    //切换项目重新加载店铺事件
    window.top.window.$("#projectSwitch").change(function () {
        setShopValue();
    });

    //初始化系统退货单列表
    // sysReturnList.initSysReturnTable();


    // 按钮绑定
    $("#btnQuickSearch").unbind("click").bind("click", sysReturnList.queryTableData);
    $("#navTabBar li").find("a[data-toggle='tab']").unbind("click").click(function () {

        $("#quickSearch").data("queryStatus", $(this).attr("id"));

        sysReturnList.queryTableData();
    });

    // 高级搜索绑定
    sysReturnList.initAdvSearch();

    $.ajax({
        type: "get",
        url: "/sysReturnManager/queryStateCount.action?quickSearch=" + encodeURI($("#quickSearch").val())
        + "&formJson=" + encodeURI(JSON.stringify($("#advSearchPanel").data("queryData"))),
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.result == "success") {
                for (var index in data.data) {
                    $("#" + data.data[index].state + "_count").html(data.data[index].num);
                }
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showModalAlert(result.errorObject.errorText);
            }
        }
    });

    if (fromother=="y"){
        if ($("#waitingAuth").text().indexOf("(0)")<0){
            $("#waitingAuth").click();
        } else if ($("#waitingReceive").text().indexOf("(0)")<0){
            $("#waitingReceive").click();
        } else if ($("#complete").text().indexOf("(0)")<0){
            $("#complete").click();
        } else if ($("#cancel").text().indexOf("(0)")<0){
            $("#cancel").click();
        } else {
            $("#waitingAuth").click();
        }
    } else {
        $("#waitingAuth").click();
    }
});

/**
 * 初始化店铺列表
 * @returns
 */
function setShopValue() {
    // 初始化店铺列表
    $.ajax({
        type: "GET",
        url: "/shop/unpagedShopList.action?prjId=" + window.top.window.$("#projectSwitch").val(),
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false,//同步
        success: function (data) {
            if (data.result == "success") {
                $("#shopId option").remove();
                $("#shopId").append("<option value=''>请选择</option>");
                $.each(data.data, function (n, value) {
                    $('#shopId').append("<option value='" + value.shopId + "' shopType = '" + value.shopType + "'>" + value.shopName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
}

/**
 * 网店变化的时候，入库仓库的值要变化
 */
$('#shopId').on('change', function () {

    if ($("#shopId").val() == "") {
        $("#storId").val("");
        $("#storId option").remove();
        $("#storId").append("<option value=''>请选择</option>");
        return;
    }

    //加载 入库仓库列表
    $.ajax({
        type: "GET",
        url: "/stor/getStorageByShopId.action?shopId=" + $("#shopId").val(),
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false,//同步
        success: function (data) {
            if (data.result == "success") {
                $("#storId option").remove();
                $("#storId").append("<option value=''>请选择</option>");
                $.each(data.data, function (n, value) {
                    $('#storId').append("<option value='" + value.storId + "'>" + value.storName + "</option>");
                });
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                alert(result.errorObject.errorText);
            }
        }
    });
});

// 初始化系统退货单列表
sysReturnList.initSysReturnTable = function () {
    $sysReturnTable = $("#sysReturnTable")
        .DataTable({
            "processing": true,
            "serverSide": true,
            "lengthMenu": [ [ 10, 25, 50, 100, 500, 1000 ], [ 10, 25, 50, 100,500,1000 ] ],
            "dom": '<"bottom"rtflp>',
            "searching": false,
            "scrollX": true,
            // "scrollXInner": "110%",
            "scrollCollapse": true,
            // "scrollY":"410px",
            "destroy": true,
            "pagingType": "full_numbers",
            // "ordering": false,
            "deferRender": true,
            "ajax": {
                "url": "/sysReturnManager/sysReturnList.action",
                "type": "get",
                // "async":false,
                "data": function (d) {
                    d.formJson = JSON.stringify($("#advSearchPanel").data("queryData"));
                    if (window.top.window.$("#returnCode").val() != "") {
                        $("#quickSearch").val(window.top.window.$("#returnCode").val());
                        window.top.window.$("#returnCode").val('');
                    }
                    d.quickSearch = encodeURI($("#quickSearch").val());
                    d.queryStatus = $("#quickSearch").data("queryStatus") ? $("#quickSearch").data("queryStatus") : $("#navTabBar").find("li.active").find("a:eq(0)").attr("id");
                }
            },
            "columns": [{
                "data": "sonShow",
                "orderable": false
            },
            /*{
                "data": "flagName",
                "className": "text-center"
            },*/ {
                "data": "finishTypeExt",
                "orderable": false,
                "className": "text-left",
                "render": function ( data, type, row, meta ) {
                    if (data == "异常完成") {
                        return "<font color='red' style='font-weight:bolder;'>异常完成</font>";
                    } else {
                        return data;
                    }
                }
            }, {
                "data": "isCancelExt",
                "orderable": false,
                "className": "text-left",
                "render" : function(data, type, row, meta ) {
                    var _returnValue = "<span title='"+row.cancelRemark+"'>"+row.isCancelExt+"</span>";
                    return _returnValue;
                }
            }, {
                "data": "returnCode",
                "className" : "truncate-text tooltip-column-detail text-left"
            }, {
                "data": "sourceCode",
                "className" : "truncate-text tooltip-column-detail text-left"
            }, {
                "data": "tradeCode",
                "className" : "truncate-text tooltip-column-detail text-left"
            },{
                "data": "lgstNo",
                "className" : "truncate-text tooltip-column-detail text-left"
            },{
                "data": "wmsStockinCode",
                "className" : "truncate-text tooltip-column-detail text-left"
            },{
                "data": "createTime",
                "className": "text-left"
            },{
                "data": "paidDate",
                "className": "text-left"
            }, {
                "data": "returnReasonName",
                "className": "text-left"
            }, {
                "data": "shopName",
                "className" : "truncate-text tooltip-column-detail text-left"
            }, {
                "data": "buyerNick",
                "orderable": false,
                "className": "text-left"
            }, {
                "data": "cons",
                "orderable": false,
                "className": "text-left"
            }, {
                "data": "storName",
                "orderable": false,
                "className": "text-left"
            }, {
                "data": "remark",
                "orderable": false,
                "className" : "truncate-text tooltip-column-detail text-left"
            }, {
                "data": "operation",
                "orderable": false,
                "className": "text-left"
            }, {
                "data": "cancelRemark",
                "visible": false
            }],
            "order": [[8, "desc"]]
        })
        .on(
            'draw.dt',
            function () {

                $("#sysReturnTable").tooltip({
                    selector: ".tooltip-column-detail",
                    container: "body",
                    title: function() {
                        if ($(this)[0].scrollWidth > $(this).outerWidth()) {
                            return $(this).text();
                        }
                    }
                });

                // setTimeout(function () {
                //     var rightWidth = $('#sysReturnTable_wrapper').find("div.DTFC_RightBodyLiner").width();
                //     var leftWidth = $('#sysReturnTable_wrapper').find("div.DTFC_LeftBodyLiner").width();
                //
                //     $('#sysReturnTable_wrapper').find("div.DTFC_LeftBodyLiner").width(leftWidth + 4);
                //     $('#sysReturnTable_wrapper').find("div.DTFC_RightBodyLiner").width(rightWidth + 4);
                // }, 1);
                // $("#sysReturnTable").find("th.sorting_asc").removeClass("sorting_asc");
                // 表格绘制完成后的回调事件
                $('#sysReturnTable td .fa-chevron-down')
                    .on(
                        'click',
                        function (event) {
                            event.stopPropagation();

                            var tr = $(this).closest("tr");
                            row = $sysReturnTable.row(tr);

                            if (row.child.isShown()) {
                                row.child.hide();
                                tr.removeClass('shown');
                                $(this).removeClass('fa-chevron-up');
                                $(this).addClass('fa-chevron-down');
                            } else {
                                // 关闭其他
                                $('#sysReturnTable tbody tr').each(function () {
                                    if ($(this).attr("role") == "row") {
                                        $sysReturnTable.row($(this)).child.hide();
                                    }
                                });

                                $('.fa-chevron-up', $('#sysReturnTable tbody')).addClass('fa-chevron-down');
                                $('.fa-chevron-down', $('#sysReturnTable tbody')).removeClass('fa-chevron-up');

                                var returnId = row.data().returnId;
                                var ifmSrc = "/views/aftersale/sysreturn/sysReturnDetail.html?returnId=" + returnId;
                                var temp = '<iframe myid="" tab="" shopType="" id="contentFrame1" name="contentFrame" style="width:100%;" frameborder="0" scrolling="auto" src="' + ifmSrc + '" width="100%" height="280"></iframe>';
                                row.child(temp).show();
                                tr.addClass("shown");
                                $(this).addClass('fa-chevron-up');
                                $(this).removeClass('fa-chevron-down');
                            }
                            return false;
                        });
                // 更新列表上TAB状态的数值
                // $.ajax({
                //     type: "get",
                //     url: "/sysReturnManager/queryStateCount.action?quickSearch=" + encodeURI($("#quickSearch").val())
                //     + "&formJson=" + encodeURI(JSON.stringify($("#advSearchPanel").data("queryData"))),
                //     contentType: "application/json;charset=utf-8",
                //     dataType: "json",
                //     async: false,
                //     success: function (data) {
                //         if (data.result == "success") {
                //             for (var index in data.data) {
                //                 $("#" + data.data[index].state + "_count").html(data.data[index].num);
                //             }
                //         } else {
                //             window.top.window.showModalAlert(data.msg);
                //         }
                //     },
                //     error: function (XMLHttpRequest, textStatus) {
                //         if (XMLHttpRequest.status == 500) {
                //             var result = eval("(" + XMLHttpRequest.responseText + ")");
                //             window.top.window.showModalAlert(result.errorObject.errorText);
                //         }
                //     }
                // });
            });
    // showCancelRemark();
};


// // 显示取消失败原因
// function showCancelRemark() {
//     $("#sysReturnTable tbody tr").each(function() {
//         var rowData = $sysReturnTable.row(this).data();
//         if (rowData != undefined && rowData.isCancelExt == "取消失败") {
//             $(this).find("td").eq(3).attr("title", rowData.cancelRemark);
//         }
//     });
// }


// 查询数据
sysReturnList.queryTableData = function () {

    var searchCondition = { // 高级检索
        shopId: $('#shopId').val(), // 店铺Id
        storId: $('#storId').val(), // 入库仓库Id
        goodsCode: $('#goodsCode').val(), // 商品商家编码
        goodsName: $('#goodsName').val(), // 商品名称
        skuCode: $('#skuCode').val(), // 规格商家编码
        skuName: $('#skuName').val(), // 规格名称
        dateType: encodeURI($('#dateType').val()), // 日期类型
        startTimeInput: $('#startTimeInput').val(), // 开始日期fng
        endTimeInput: $('#endTimeInput').val(), // 截止日期
        factStockin: $('#factStockin').get(0).checked ? "y" : "n", // 实际入库
        hasRerutnInfo: $('#hasRerutnInfo').get(0).checked ? "y" : "n"  // 已填写退货信息
    };

    $("#advSearchPanel").data("queryData", searchCondition);

    var queryData = $("#advSearchPanel").data("queryData");
    if (null == $sysReturnTable) {
        sysReturnList.initSysReturnTable();
    } else {

        var optionData = $sysReturnTable.settings()[0].ajax.data;
        if (optionData.formJson) {
            optionData.formJson = JSON.stringify($.extend(true, {}, $.parseJSON(optionData.formJson), queryData));
        }
        optionData.quickSearch = encodeURI($("#quickSearch").val());
        optionData.queryStatus = $("#quickSearch").data("queryStatus");

        $sysReturnTable.settings()[0].ajax.data = optionData;
        $sysReturnTable.ajax.reload();
    }
    // showCancelRemark();
    $.ajax({
        type: "get",
        url: "/sysReturnManager/queryStateCount.action?quickSearch=" + encodeURI($("#quickSearch").val())
        + "&formJson=" + encodeURI(JSON.stringify($("#advSearchPanel").data("queryData"))),
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.result == "success") {
                for (var index in data.data) {
                    $("#" + data.data[index].state + "_count").html(data.data[index].num);
                }
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showModalAlert(result.errorObject.errorText);
            }
        }
    });
}

/*
 * 刷新系统退货单列表
 */
sysReturnList.refresh = function () {
    $('#quickSearch').val("");
    quickSearch = "";
    $("#advSearchReset").click();
    searchCondition = {};
    if (!$("#advSearchPanel").is(":hidden")){
        $("#btnAdvSearch").click();
    }
    sysReturnList.queryTableData();
};

// 重置按钮
$("#advSearchReset").click(function () {
    $('#goodsCode').val('');
    $('#goodsName').val('');
    $('#skuCode').val('');
    $('#skuName').val('');
});

// 高级查询中的时间类型变更的时候，开始时间，截止日期的控件赋值，显示，不显示
$("#dateType").bind("change", function () {
//        if (this.value== "苹果")
    switch (this.value) {
        case "请选择":
            $("#startTimeInput").val("");
            $("#hidstartTimeInput").val("");
            $("#endTimeInput").val("");
            $("#hidendTimeInput").val("");
            $(".input-group-addon").hide();
            break;
        default:
            $(".input-group-addon").show();
            break;
    }
});


/*
 * 导出退货单列表
 */
sysReturnList.exportSysReturn = function () {
    exportList('$sysReturnTable', '/sysReturnManager/exportCheck.action', '/sysReturnManager/export.action', 'exportSelectItem', '系统退货单导出', 'frmAdvSearch', "");
};

sysReturnList.initAdvSearch = function () {
    btnAdvSearchflg = false;
    /**
     * 搜索框的回车事件
     */
    $('#quickSearch').keydown(function (e) {
        if (e.keyCode == 13 && $('#btnQuickSearch').is(":visible")) {
            $("#btnQuickSearch").click();
        }
    });

    // 高级搜索
    $("#btnAdvSearch").click(function () {
        btnAdvSearchflg = true;
        if ($("#advSearchPanel").is(":hidden")) {
            $("#advSearchPanel").show();
            $("#btnQuickSearch").hide();
            $(this).children("i:eq(0)").removeClass("fa-angle-double-down");
            $(this).children("i:eq(0)").addClass("fa-angle-double-up");
        } else {
            $("#advSearchPanel").hide();
            $("#btnQuickSearch").show();
            $(this).children("i:eq(0)").removeClass("fa-angle-double-up");
            $(this).children("i:eq(0)").addClass("fa-angle-double-down");
        }
    });

    $("#advSearchPanel").click(function () {
        btnAdvSearchflg = true;
    })

    // /**
    //  * body点击的时候高级检索收回
    //  */
    // $("body").click(function (e) {
    //     if (btnAdvSearchflg == true) {
    //         btnAdvSearchflg = false;
    //     } else {
    //         $("#advSearchPanel").hide();
    //         $("#btnAdvSearch").children("i:eq(0)").removeClass("fa-angle-double-up");
    //         $("#btnAdvSearch").children("i:eq(0)").addClass("fa-angle-double-down");
    //     }
    // });





    // 高级搜索“提交”按钮点击
    $("#advSearchSubmit").click(function (e) {
        var searchCondition = { // 高级检索
            shopId: $('#shopId').val(), // 店铺Id
            storId: $('#storId').val(), // 入库仓库Id
            goodsCode: $('#goodsCode').val(), // 商品商家编码
            goodsName: $('#goodsName').val(), // 商品名称
            skuCode: $('#skuCode').val(), // 规格商家编码
            skuName: $('#skuName').val(), // 规格名称
            dateType: encodeURI($('#dateType').val()), // 日期类型
            startTimeInput: $('#startTimeInput').val(), // 开始日期fng
            endTimeInput: $('#endTimeInput').val(), // 截止日期
            factStockin: $('#factStockin').get(0).checked ? "y" : "n", // 实际入库
            hasRerutnInfo: $('#hasRerutnInfo').get(0).checked ? "y" : "n"  // 已填写退货信息
        };

//         $("#quickSearch").val("");
        $("#advSearchPanel").data("queryData", searchCondition);
        // $("#btnAdvSearch").children("i:eq(0)").removeClass("fa-angle-double-up");
        // $("#btnAdvSearch").children("i:eq(0)").addClass("fa-angle-double-down");

        sysReturnList.queryTableData();
    });


    var searchCondition = { // 高级检索
        shopId: $('#shopId').val(), // 店铺Id
        storId: $('#storId').val(), // 入库仓库Id
        goodsCode: $('#goodsCode').val(), // 商品商家编码
        goodsName: $('#goodsName').val(), // 商品名称
        skuCode: $('#skuCode').val(), // 规格商家编码
        skuName: $('#skuName').val(), // 规格名称
        dateType: encodeURI($('#dateType').val()), // 日期类型
        startTimeInput: $('#startTimeInput').val(), // 开始日期fng
        endTimeInput: $('#endTimeInput').val(), // 截止日期
        factStockin: $('#factStockin').get(0).checked ? "y" : "n", // 实际入库
        hasRerutnInfo: $('#hasRerutnInfo').get(0).checked ? "y" : "n"  // 已填写退货信息
    };

    $("#advSearchPanel").data("queryData", searchCondition);

}

// 设置时间区间，用于区间的初始化和区间控件选择后的回调
sysReturnList.setdaterange = function (start, end) {
    $('.reportrange span').html(start.format('YYYY-MM-DD HH:mm') + ' - ' + end.format('YYYY-MM-DD HH:mm'));
    $('input[name="datestart"]').val(start.format("YYYY-MM-DD HH:mm"));
    $('input[name="dateend"]').val(end.format("YYYY-MM-DD HH:mm"));
};

//修改退货单
sysReturnList.operationEdit = function(btnObj) {
    if (btnObj) {
        var sysReturnId = $(btnObj).attr("returnId");
        if (!!sysReturnId) {
            var iframeSrc = "./views/aftersale/sysreturn/sysReturnEdit.html?sysReturnId=" + sysReturnId;
            // 新增的界面样例
            $("#ifmSysReturnDetail").attr("src", iframeSrc);
            $("#btnSave").unbind("click").bind("click",function() {
                    // 调用子页面的保存方法
                    window.top.frames["ifmSysReturnDetail"].window.sysReturnEdit
                        .saveSysReturn(window.top.frames["ifmSysReturnDetail"].contentWindow);
                });
            var sysReturnDetailDialog = window.top.window.borrowCustomModalDialog($("#modalSysReturnDetail"));
            sysReturnDetailDialog.on('hide.bs.modal', function() {
                // 父窗体归还本页的编辑对话框
                window.top.window.returnCustomModalDialog();
                sysReturnList.refresh();
            });
            sysReturnDetailDialog.modal({
                show : true,
                backdrop : 'static'
            });
        }
    }
};

//删除系统退货单
sysReturnList.operationDelete = function (btnObj) {
    if (btnObj) {
        var returnId = $(btnObj).attr("returnId");
        if (!!returnId) {
            window.top.window.showModalConfirm("确定要删除吗", function () {
                sysReturnList.operation.Delete(returnId);
            });
        }

    }
}

// 删除系统退货单
sysReturnList.operation.Delete = function (sysReturnIds) {
	var loading = window.top.window.getIndexBusyOverlay();
    $.ajax({
        type: "GET",
        url: "/sysReturnManager/deleteSysReturn.action",
        contentType: "application/json;charset=utf-8",
        data: {
            "returnIds": sysReturnIds
        },
        dataType: "json",
//        async: false,
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
        success: function (data) {
        	loading.remove();
            if (data.result == "success") {
                window.top.window.showScoMessage('ok', data.msg);
                sysReturnList.queryTableData();
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error: function (XMLHttpRequest, textStatus) {
        	loading.remove();
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showScoMessage('error', result.errorObject.errorText);
            }
        }
    });
}

// 审核按钮点击事件
sysReturnList.authen = function(returnId,returnCode) {
    // var returnId = $(btnObject).attr("returnId");
    // var ddsss = $(btnObject).attr("returnCode");
    if (!!returnId) {
        window.top.window.showModalConfirms("确定要审核吗", function () {
            sysReturnList.operation.authenCheck(returnId,returnCode);
        });
    }
};

// 审核校验：退货快递单号和退回物流公司不能为空
sysReturnList.operation.authenCheck = function(sysReturnIds,sysReturnCodes) {
    $.ajax({
        type : "GET",
        url : "/sysReturnManager/apprSysReturnCheck.action",
        contentType : "application/json;charset=utf-8",
        data : {
            "returnIds" : sysReturnIds,
            "returnCodes" : sysReturnCodes
        },
        dataType : "json",
        async : false,
        success : function(data) {

            if (data.result == "success") {
                if (data.message.length > 0) {
                    var apprResult = $.parseJSON(data.message[0].message);
                    if (apprResult.result == "success") {
                        sysReturnList.operation.authen(sysReturnIds,sysReturnCodes);
                    } else if (apprResult.result == "failed") {
                        window.top.window.showModalConfirms("退货快递单号或退回物流公司为空，是否继续审核？", function () {
                        sysReturnList.operation.authen(sysReturnIds,sysReturnCodes);});
                    }
                }
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showScoMessage('error', result.errorObject.errorText);
            }
        }
    });
};

// 审核
sysReturnList.operation.authen = function(sysReturnIds,sysReturnCodes) {
	var loading = window.top.window.getIndexBusyOverlay();
    $.ajax({
        type : "GET",
        url : "/sysReturnManager/apprSysReturn.action",
        contentType : "application/json;charset=utf-8",
        data : {
            "returnIds" : sysReturnIds,
            "returnCodes" : sysReturnCodes
        },
        dataType : "json",
//        async : false,
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        }, 
        success : function(data) {
        	loading.remove();
            if (data.result == "success") {
                if (data.message.length > 0) {
                    var apprResult = $.parseJSON(data.message[0].message);
                    if (apprResult.result == "success") {
                        window.top.window.showScoMessage('ok', "审核成功");
                        sysReturnList.queryTableData();
                    } else if (apprResult.result == "failed") {
                        var showingMessage = "当前退货单审核不通过,存在未发货系统商品如下：<br/>"
                        for ( var index in apprResult.detail[0]) {
                            var detailItem = apprResult.detail[0][index];
                            var msg = "单据编号："+detailItem.sourceCode+ "，规格商家编码："+detailItem.skuCode;
                                showingMessage += msg + "<br/>";                        }
                        window.top.window.showModalAlertPretty(showingMessage);
                    }else if(apprResult.result == "errors"){
                        window.top.window.showScoMessage('error', "审核失败");
                    }
                }
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
        	loading.remove();
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showScoMessage('error', result.errorObject.errorText);
            }
        }
    });
};



// 取消按钮点击事件
sysReturnList.cancel = function(btnObject) {
    var returnId = $(btnObject).attr("returnId");
    if (!!returnId) {
        window.top.window.showModalConfirm("确定要取消吗", function () {
            sysReturnList.operation.cancel(returnId);
        });
    }
};

// 取消
sysReturnList.operation.cancel = function(sysReturnIds) {
	var loading = window.top.window.getIndexBusyOverlay();
    $.ajax({
        type : "GET",
        url : "/sysReturnManager/cancelSysReturn.action",
        contentType : "application/json;charset=utf-8",
        data : {
            "returnIds" : sysReturnIds
        },
        dataType : "json",
//        async : false,
        beforeSend:function(){
            if(loading) {
            	loading.settext("正在处理中，请稍后...");
            }
        },
        success : function(data) {
        	loading.remove();
            if (data.result == "success") {
                if (data.message.length > 0) {
                    var apprResult = $.parseJSON(data.message[0].message);
                    if (apprResult.result == "success") {
                        window.top.window.showScoMessage('ok', "取消成功");
                        sysReturnList.queryTableData();
                    } else if (apprResult.result == "failed") {
                        window.top.window.showScoMessage('error', "取消失败");
                        sysReturnList.queryTableData();
                    }
                }
            } else {
                window.top.window.showModalAlert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus) {
        	loading.remove();
            if (XMLHttpRequest.status == 500) {
                var result = eval("(" + XMLHttpRequest.responseText + ")");
                window.top.window.showScoMessage('error', result.errorObject.errorText);
            }
        }
    });
};




